package com.xinxin.facelinker.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;

import com.easemob.chatuidemo.R;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.xinxin.facelinker.domain.ShowToplist;
import com.xinxin.facelinker.ui.grid.util.DynamicHeightImageView;
import com.xinxin.facelinker.ui.grid.util.DynamicHeightTextView;

import java.util.List;

/**
 * Created by gengliang on 2015/8/21.
 */
public class ToplistAdapter extends BaseAdapter {

    private Context context;
    private List<ShowToplist> list;
    private ImageLoader imageLoader= ImageLoader.getInstance();

    public Context getContext() {
        return context;
    }

    public void setContext(Context context) {
        this.context = context;
    }

    public List<ShowToplist> getList() {
        return list;
    }

    public void setList(List<ShowToplist> list) {
        this.list = list;
    }

    public ToplistAdapter(Context context, List<ShowToplist> list) {

        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        LinearLayout linearLayout;

        if (convertView != null) {
            linearLayout = (LinearLayout) convertView;
        } else {
            linearLayout = (LinearLayout) LayoutInflater.from(getContext()).inflate(R.layout.layout_show_toplist, null);
        }

        ShowToplist showToplist = list.get(position);

        DynamicHeightImageView ivToplist = (DynamicHeightImageView) linearLayout.findViewById(R.id.ivToplist);
        DynamicHeightTextView tvMotion = (DynamicHeightTextView) linearLayout.findViewById(R.id.tvMotion);

        imageLoader.displayImage(showToplist.getPhoto_url(), ivToplist);
        tvMotion.setText(showToplist.getMotion());

        return linearLayout;
    }
}
